<template>
  <div class="app-container">
    <div class="filter-container" >
      <el-select  v-model="value" placeholder="选择类型" class="filter-item" style="float: left;">
         <el-option style="text-align: center;" label="全部订单" value="1">全部订单</el-option>
         <el-option style="text-align: center;"  label="免费订单"  value="2"></el-option>
         <el-option style="text-align: center;" label="付费订单" value="3"></el-option>
      </el-select>
      <el-button v-waves class="filter-item" style="float: left;margin-left: 10px;" type="warning" icon="el-icon-zoom-in" @click="handleType">
        查询
     </el-button>
      <el-input  v-model="searchname" placeholder="elasticSearch根据订单号或资料名搜索" style="width: 400px;margin-right: 10px;margin-left: 30px;" class="filter-item" @keyup.enter.native="handleFilter" />
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleSearch">
        搜索
      </el-button>

    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"

    >
     <el-table-column align="center" label="序号" width="95">
              <template slot-scope="row">
                {{ row.$index+1 }}
              </template>
            </el-table-column>
      <el-table-column label="订单号" width="200px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.orderId }}</span>
        </template>
      </el-table-column>
      <el-table-column label="资料名称" width="300px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.goodName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" width="100px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.orderType}}</span>
        </template>
      </el-table-column>
      <el-table-column label="金额(¥)" width="150px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.price }}</span>
        </template>
      </el-table-column>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200px" class-name="small-padding fixed-width">
        <template slot-scope="{row,$index}">
          <el-button type="primary" icon="el-icon-s-order" size="mini" @click="findDetailOrder(row)">
            详情
          </el-button>
          <el-button v-if="checkPermission([1])"  icon="el-icon-delete"  size="mini" type="danger" @click="handleDelete(row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <el-dialog  :visible.sync="dialogFormVisible" >
      <el-form  :model="orderDetail" label-width="70px" style="width: 400px;margin-left: 20%;" >
        <el-form-item label="订单号" prop="orderNumber">
          <el-input v-model="orderDetail.orderNumber" />
        </el-form-item>
        <el-form-item  label="用户名" prop="username">
          <el-input v-model="orderDetail.username" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="orderDetail.phone"  />
        </el-form-item>
        <el-form-item label="资料名称" prop="goodName">
          <el-input v-model="orderDetail.goodName" />
        </el-form-item>
        <el-form-item label="价格(¥)" prop="price">
          <el-input v-model="orderDetail.price" placeholder="输入QQ号"/>
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="orderDetail.message" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="Please input" />
        </el-form-item>
        <el-form-item label="图片" prop="">
           <img :src="'http://139.159.144.167:80/'+orderDetail.images" style="width: 300px;height: 150px;">
        </el-form-item>

        </el-form>
    </el-dialog>

  </div>
</template>

<script>
import {findType,searchOrder,findDetail,delOrder} from '@/api/order'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import checkPermission from '@/utils/permission' // 权限判断函数

export default {
  name: 'ComplexTable',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      orderDetail:{
        orderNumber:null,
        username:null,
        phone:null,
        goodName:null,
        message:null,
        images:null,
        price:null
      },
      typeId:1,
      value: null,
      searchname:null,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        searchName:null,
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '修改',
        create: ''
      },
      dialogPvVisible: false,
      downloadLoading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
     checkPermission,
     handleType(){
       this.typeId=this.value
       this.getList()
       this.typeId=1
     },
    findDetailOrder(row){
      var query={
        orId:row.orId,
        orderId:row.orderId,
        userId:row.userId,
        goodId:row.goodId
      }
      findDetail(query).then(res=>{
         this.orderDetail =res.data
        this.dialogFormVisible=true
      })
    },
    getList() {
      this.listLoading = true
      var query={
          "limit":this.listQuery.limit,
          "page":this.listQuery.page,
          "typeId":this.typeId
        }
        findType(query).then(response => {
          this.list = response.data.items
          this.total = response.data.total
          setTimeout(() => {
            this.listLoading = false
          }, 1.5 * 1000)
        })
      },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },


    handleDelete(row) {
		var query={
			orId:row.orId,
			orderId:row.orderId
		}
		delOrder(query).then(res=>{
			this.$notify({
			title: 'Success',
			message: 'Delete Successfully',
			type: 'success',
			duration: 2000
		})
       this.getList()
      })

    },
    handleSearch(){
      if(this.searchname==null||this.searchname==''){
         this.getList();
      }else{
     searchOrder(this.searchname).then(res=>{
          this.total=res.data.total,
          this.list=res.data.items
        })
      }

    }
  }
}
</script>
